package com.leo.tool.http;


import org.junit.Ignore;
import org.junit.Test;

public class HttpDemo {

    //免费的在线REST服务, 提供测试用的HTTP请求假数据
    //接口信息说明可见：http://www.hangge.com/blog/cache/detail_2020.html
    String uri = "http://jsonplaceholder.typicode.com";

    //get方式请求数据
    //请求地址：http://jsonplaceholder.typicode.com/posts
    @Ignore("暂时忽略")
    @Test
    public void test1() {
        System.out.print("\n" + "test1---------------------------"+ "\n");
        HttpParamers paramers = HttpParamers.httpGetParamers();
        String response = "";
        try {
            HttpService httpService = new HttpService(uri);
            response = httpService.service("/posts", paramers);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.print(response);
    }

    //get方式请求数据
    //请求地址：http://jsonplaceholder.typicode.com/posts?userId=5
    @Ignore("暂时忽略")
    @Test
    public void test2() {
        System.out.print("\n" + "test2---------------------------"+ "\n");
        HttpParamers paramers = HttpParamers.httpGetParamers();
        paramers.addParam("userId", "5");
        String response = "";
        try {
            HttpService httpService = new HttpService(uri);
            response = httpService.service("/posts", paramers);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.print(response);
    }

    //post方式请求数据
    //请求地址：http://jsonplaceholder.typicode.com/posts
    @Test
    public void test3() {
        System.out.print("\n" + "test3---------------------------"+ "\n");
        HttpParamers paramers = HttpParamers.httpPostParamers();
        paramers.addParam("time", String.valueOf(System.currentTimeMillis()));
        String response = "";
        try {
            HttpService httpService = new HttpService(uri);
            response = httpService.service("/posts", paramers);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.print(response);
    }
}
